<template>
	<view class="bg-white flex" style="height: 100vh; width: 100vw;">
		<scroll-view scroll-y="true" style="height: 100%;width: 100%;">
			<cu-custom bgColor="bg-white" :isBack="true">
				<block slot="content">
					<text class="text-black" style="font-size: 32rpx;">私信</text>
				</block>
				<block v-if="develop" slot="right">
					<text class="text-black" style="font-size: 32rpx;">设置</text>
				</block>
			</cu-custom>
			<view v-for="(targetUser, index) in targetUserList" :key="index" @click="goToChat(targetUser)" class="flex align-center solid-bottom" style="padding: 24rpx 32rpx;">
				<view class="cu-avatar round" style="height: 96rpx; width: 96rpx;" :style="{'background-image':'url('+targetUser.avatar+')'}"></view>
				<view class="flex flex-direction justify-between" style="margin-left: 16rpx;">
					<text style="font-size: 32rpx; color: #333333; font-weight: bold;">{{targetUser.username}}</text>
					<text style="font-size: 28rpx; color: #999999;margin-top: 8rpx;display: -webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:2 ;overflow:hidden;">
						{{targetUser.text}}
					</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: this.$store.getters.userid,
				targetUserList: [],
			}
		},
		methods: {
			goToChat(targetUser) {
				let targetUserId = targetUser.receiveId==this.userId ? targetUser.sendId:targetUser.receiveId;
				let targetUserName = targetUser.username;
				let targetAvatar = targetUser.avatar;
				let develop = this.develop;
				
				// #ifndef APP-PLUS
				this.$Router.push({
					name: 'chat',
					params: {
						targetUserId: targetUserId,
						targetUserName: targetUserName,
						targetAvatar: targetAvatar,
						develop: develop
					}
				})
				// #endif
				
				// #ifdef APP-PLUS
				uni.navigateTo({
					url: `/pages/chat/chat?targetUserId=${targetUserId}&targetUserName=${targetUserName}&targetAvatar=${targetAvatar}&develop=${develop}`
				})
				// #endif
			}
		},
		onLoad() {
		},
		onShow() {
			this.$http.get('/ucenter/message/getMemberList/' + this.userId).then(res=>{
				let data = res.data;
				if(data.success) {
					this.targetUserList = data.result;
					this.targetUserList.forEach(item => {
						const context = JSON.parse(item.context);
						item.text = context.context;
						item.receiveId = context.receiveId;
						item.sendId = context.sendId;
					})
				}
			})
		}
	}
</script>

<style>
</style>
